package com.xiyuan.smartutils.control;

import java.util.List;

/**
 * 处理器适配成可执行对象，以便在Threader中处理时转换成Handler中处理
 *
 * @version v1.0.0 @author lgz 2017-8-27 新建与整理
 */
class Eventee<E> implements Runnable
{
    private E event;
    private List<Eventor<E>> eventerList;
    
    public Eventee(E event, List<Eventor<E>> eventerList)
    {
        this.event = event;
        this.eventerList = eventerList;
    }
    
    @Override
    public void run()
    {
        for (Eventor<E> eventer : eventerList)
        {//按注册顺序冒泡处理
            if (!eventer.process(event))
                break;
        }
    }

    public E getEvent()
    {
        return event;
    }

    public List<Eventor<E>> getEventerList()
    {
        return eventerList;
    }
    
    public int hasCode()
    {
        return event.hashCode();
    }
    
    public boolean equals(Object obj) 
    {
        if (obj == null)
            return false;
        
        if (!(obj instanceof Eventee<?>))
            return false;
        
        Eventee<?> other = (Eventee<?>)obj;
        if (other.event == null)
            return this.event == null;
        else
            return (other.event.equals(this.event));
    }
    
    public String toString()
    {
        return event.toString();
    }
}
